package de.slothsoft.dome.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DoMeSqlHelper extends SQLiteOpenHelper {

	public static final String TABLE_TODOS = "todos";

	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_TODO_NAME = "name";
	public static final String COLUMN_TODO_DESCRIPTION = "description";

	public static final String[] COLUMNS_TODO = { COLUMN_ID, COLUMN_TODO_NAME,
			COLUMN_TODO_DESCRIPTION };

	private static final String DATABASE_NAME = "todos.db";
	private static final int DATABASE_VERSION = 1;

	private static final String DATABASE_CREATE =
	// TABLE TODOS
	"CREATE TABLE " + TABLE_TODOS + //
			"(" + COLUMN_ID + " integer primary key autoincrement, " + //
			COLUMN_TODO_NAME + " text not null, " + //
			COLUMN_TODO_DESCRIPTION + " text); ";

	public DoMeSqlHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(DoMeSqlHelper.class.getName(), "Upgrading database from version "
				+ oldVersion + " to " + newVersion
				+ ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_TODOS);
		onCreate(db);
	}

}